package com.compass.doctor.ui.home.viewmodel

import androidx.lifecycle.MutableLiveData
import com.compass.framework.model.ArticleOrVideo
import com.compass.framework.model.Comment
import com.compass.framework.model.Inventory
import com.compass.framework.model.KnowledgeCenter
import com.compass.framework.model.Message
import com.compass.framework.model.OrderSpecial
import com.compass.framework.toast.TipsToast
import com.compass.network.callback.IApiErrorCallback
import com.compass.network.manager.ApiManager
import com.compass.network.viewmodel.BaseViewModel

/**
 * Description： 知识中心viewModel
 * Date:2023/12/24 15:59
 */
class KnowledgeCenterViewModel :BaseViewModel() {

    val knowledgeLiveData: MutableLiveData<KnowledgeCenter?> = MutableLiveData()
    val commentLiveData: MutableLiveData<MutableList<Comment>?> = MutableLiveData()
    val specialLiveData: MutableLiveData<MutableList<OrderSpecial>?> = MutableLiveData()
    val articleLiveData: MutableLiveData<MutableList<ArticleOrVideo>?> = MutableLiveData()
    val videoLiveData: MutableLiveData<MutableList<ArticleOrVideo>?> = MutableLiveData()
    val shareLiveData = MutableLiveData<Any?>()
    fun getKnowledgeInfo() {
        launchUIWithResult(responseBlock = {
            ApiManager.api.getKnowledgeInfo()
        }, errorCall = object : IApiErrorCallback {
            override fun onError(code: Int?, error: String?) {
                TipsToast.showTips(error)
                knowledgeLiveData.value =null
            }
        }, successBlock = {
            if (it == null ) {
                knowledgeLiveData.value =null
            } else {
                knowledgeLiveData.value = it
            }
        })
    }


    fun getComment(page:Int) {
        launchUIWithResult(responseBlock = {
            ApiManager.api.getComment(page, pageSize = 10)
        }, errorCall = object : IApiErrorCallback {
            override fun onError(code: Int?, error: String?) {
                TipsToast.showTips(error)
                commentLiveData.value =null
            }
        }, successBlock = {
            if (it == null || it.list.isNullOrEmpty() ) {
                commentLiveData.value =null
            } else {
                commentLiveData.value = it.list
            }
        })
    }

    fun getOrderSpecial(page:Int) {
        launchUIWithResult(responseBlock = {
            ApiManager.api.getOrderSpecial(page, pageSize = 10)
        }, errorCall = object : IApiErrorCallback {
            override fun onError(code: Int?, error: String?) {
                TipsToast.showTips(error)
                specialLiveData.value =null
            }
        }, successBlock = {
            if (it == null || it.list.isNullOrEmpty() ) {
                specialLiveData.value =null
            } else {
                specialLiveData.value = it.list
            }
        })
    }

    fun getArticlePage(page:Int,keyword :String?,separate:String?=null) {
        launchUIWithResult(responseBlock = {
            ApiManager.api.articlePage(page, pageSize = 10,keyword,separate)
        }, errorCall = object : IApiErrorCallback {
            override fun onError(code: Int?, error: String?) {
                TipsToast.showTips(error)
                articleLiveData.value =null
            }
        }, successBlock = {
            if (it == null || it.list.isNullOrEmpty() ) {
                articleLiveData.value =null
            } else {
                articleLiveData.value = it.list
            }
        })
    }

    fun getVideoPage(page:Int,keyword :String?,separate:String?=null) {
        launchUIWithResult(responseBlock = {
            ApiManager.api.videoPage(page, pageSize = 10,keyword,separate)
        }, errorCall = object : IApiErrorCallback {
            override fun onError(code: Int?, error: String?) {
                TipsToast.showTips(error)
                videoLiveData.value =null
            }
        }, successBlock = {
            if (it == null || it.list.isNullOrEmpty() ) {
                videoLiveData.value =null
            } else {
                videoLiveData.value = it.list
            }
        })
    }


    fun articleAndVideoShare(id:String,patientId :String) {
        launchUIWithResult(responseBlock = {
            ApiManager.api.articleAndVideoShare(id,patientId)
        }, errorCall = object : IApiErrorCallback {
            override fun onError(code: Int?, error: String?) {
                TipsToast.showTips(error)
                shareLiveData.value=null
            }
        }, successBlock = {
            shareLiveData.value=it
        })
    }
}